import { getAreaObj } from '@/utils/util'
import { BaseFormConfig } from './components/config'
import { toSearchHandle, configToSearch, configToReserveSearch } from '@/views/datacenter/comprehensiveQueries/components/NewKeywords/components/utils/index'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '所属区域', prop: 'tableAreaName', width: 200 },
		{ label: '组织名称', prop: 'orgHomeName' },
		{
			label: '统一社会信用代码',
			prop: 'creditCode',
		},
		{ label: '联系人', prop: 'contactUserName' },
		{ label: '联系方式', prop: 'contactUserPhone', plusXing: '5,2' },
		{
			label: '经营状态',
			prop: 'operateStatusLabel',
		},
		{
			label: '经营范围',
			prop: 'serviceScope',
		},
		{ label: '入库时间', prop: 'createTime' },
		{
			label: '上链状态',
			prop: 'onBlockchainFlag',
			api: 'geiDictItemList',
			type: 'remoteSelect',
			code: 'BLOCK_CHAIN_STATUS',
			tipProp: 'onBlockchainTime',
			tipLabel: '上链时间',
		},
		{
			label: '操作',
			prop: 'menu',
			fixed: 'right',
      width:200
		},
	],
}
export const detailConfig = {
	customeHeader: {
		type: 'CardOne',
		title: 'orgHomeName',
		avatar: 'orgHomeLogo',
		tipList: [{ prop: 'operateStatusLabel', type: 'tip-success', label: '运营状态' }],
		tagList: [
			{ prop: 'organizationEvaluateScore', value: '未评', custome: 'tag', type: 'success', label: '评价分' },
			{ prop: 'creditCode', type: 'success', label: '统一社会信用代码：' },
		],
		menuBtn: [
			// {
			// 	icon: 'delete',
			// 	label: '删除服务组织',
			// 	type: 'danger',
			// 	operate: 'delete',
			// 	hide: 'dataStatus!==0',
			// 	auth: 'view_dpServiceOrgHome_del',
			// 	text: false,
			// 	show: true,
			// 	plain: true,
			// },
		],
	},
}
const reserveSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToReserveSearch(BaseFormConfig.column)],
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(BaseFormConfig.column)],
}
export const baseConfig = {
	pageName: '养老服务运营单位',
	dictcodes: [
		'BLOCK_CHAIN_STATUS',
		'COMMON_FLAG',
		'ORG_OPERATE_STATUS',
		'ORG_LEVEL',
		'LEGAL_PROPERTY',
		'REGISTER_TYPE',
		'ID_CARD_TYPE',
		'DEPUTY_TYPE',
		'LEGAL_PROPERTY',
	],
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'orgHomeName',
	needPigeonhole: true, // 是否显示顶部关于归档的部分
	exportMqTopic: '/ning/export/',
	api: {
		moreSearch: 'view_dpServiceOrgHome_search',
		reserveSearch: 'view_dpServiceOrgHome_search',
		index: 'dpServiceOrgHome_page',
		add: 'dpServiceOrgHome_gather',
		edit: 'dpServiceOrgHome_edit',
		delete: 'dpServiceOrgHome_del',
		export: 'dpServiceOrgHome_export',
	},
	auth: {
		index: 'view_dpServiceOrgHome_page',
		add: 'view_dpServiceOrgHome_gather',
		edit: 'view_dpServiceOrgHome_edit',
		delete: 'view_dpServiceOrgHome_del',
		detail: 'view_dpServiceOrgHome_view',
		mulitSet: 'mulitSet',
		import: 'view_dpServiceOrgHome_import',
		export: 'view_dpServiceOrgHome_export',
	},
	paramsObj: {
		code: 3035,
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'view_dpServiceOrgHome_view',
			text: true,
			show: true,
		},
	],
	moreSearchConfig,
	reserveSearchConfig,
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	dialogConfig: {
		width: '65%',
		// fullscreen: true
	},
	detailConfig: detailConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '信用代码',
				prop: 'creditCode',
				type: 'input',
				span: 6,
			},
			{
				label: '机构名称',
				prop: 'orgHomeName',
				type: 'input',
				span: 6,
			},
			{
				label: '联系人',
				prop: 'contactUserName',
				type: 'input',
				span: 6,
			},
			{
				label: '联系方式',
				prop: 'contactUserPhone',
				type: 'input',
				span: 6,
			},
			{
				label: '所属区域',
				prop: 'region',
				// propName: 'region_name',
				type: 'AplidAreaSelect',
				span: 6,
			},
			// {
			// 	label: '注册类型',
			// 	prop: 'registerType',
			// 	type: 'remoteSelect',
			// 	api: 'getDictItemList',
			// 	code: 'REGISTER_TYPE',
			// 	filterKey: 'value',
			// 	span: 6,
			// },
			{
				label: '机构星级',
				prop: 'organizationLevel',
				type: 'remoteSelect',
				api: 'getDictItemList',
				code: 'ORG_LEVEL',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
			{
				label: '运营状态',
				prop: 'operateStatus',
				type: 'remoteSelect',
				api: 'getDictItemList',
				code: 'ORG_OPERATE_STATUS',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
		],
	},

	beforeOnLoadFormate: async (params) => {
		
		const regionObj: any = getAreaObj(params.region, '')
		console.log(regionObj)
		params = toSearchHandle(moreSearchConfig, reserveSearchConfig, params)
		return Promise.resolve({
			...params,
			...regionObj,
			areas: undefined,
			region: undefined,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areasObj: any = getAreaObj(item, 'now', 'set')
			const regionObj: any = getAreaObj(item, '', 'set')
			return {
				...item,
				areas_name: areasObj.names,
				areas: areasObj.areaIds,
				region:regionObj.areaIds,
				region_name:regionObj.names,
				tableAreaName: [item.areaName, item.streetName, item.communityName].filter(Boolean).join(''),
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	tableConfig,
}
